/**
 * @param {number} startAt
 * @param {number} moveCost
 * @param {number} pushCost
 * @param {number} targetSeconds
 * @return {number}
 */
 var minCostSetTime = function(startAt, moveCost, pushCost, targetSeconds) {
  const mins = Math.floor(targetSeconds/60), sec = targetSeconds % 60
  const getNum = (m, s) => {
    let head = String(m), tail = String(s)
    if(m > 0 && s < 10) tail = '0'+tail
    if(m === 0) head = ''
    return head + tail
  }
  let pos = [getNum(mins, sec)]
  if(sec + 60 <= 99 && mins > 0){
    pos.push(getNum(mins-1, sec+60))
  }
  for(let i = 0, len = pos.length; i<len; i++){
    if(pos[i].length === 3 || pos[i].length === 2) pos.push('0'+pos[i])
  }
  pos = pos.filter(v => v.length < 5)
  let ans = Infinity
  for(let s of pos){
    let cost = 0
    const arr = s.split('').map(v => Number(v))
    let pre = -1
    for(let i = 0; i<arr.length; i++){
      if(i === 0 && arr[i] === startAt){
        cost += pushCost
      }else if(arr[i] === pre){
        cost += pushCost
      }else{
        cost += moveCost + pushCost
      }
      pre = arr[i]
    }
    ans = Math.min(ans, cost)
  }
  return ans
};